package com.mrzhou.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mrzhou.system.entity.Role;
import com.mrzhou.core.tool.api.R;
import com.mrzhou.core.tool.constants.CloudConstant;
import com.mrzhou.core.tool.utils.Func;
import com.mrzhou.system.mapper.RoleMapper;
import com.mrzhou.system.service.IRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl  extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Override
    public List<String> getRoleAlias(String roles) {
        return this.baseMapper.getRoleAlias(Func.toLongArray(roles));
    }

    public List<String> getRolePerms(String roles) {
        return this.baseMapper.getRolePerms(Func.toLongArray(roles));
    }

    @Override
    public R<String> submit(Role role) {
        if(role.getParentId() == null && role.getId() == null) {
            role.setParentId(CloudConstant.TOP_PATENT_ID);
        }
        role.setIsDelete(CloudConstant.DEFAULT_NOT_DELETE);
        return R.status(this.saveOrUpdate(role));
    }

}
